const { defineConfig } = require('vite')
const path = require('path')
const vue = require('@vitejs/plugin-vue')

const isPrd = process.env.NODE_ENV === 'production'
console.log('isPrd: ', isPrd)
console.log('process.env.NODE_ENV: ', process.env.NODE_ENV)

module.exports = defineConfig({
  plugins: [vue()],
  build: {
    lib: {
      entry: path.resolve(__dirname, 'src/lib/main.ts'),
      name: 'PluginComponents',
      fileName: format => `plugin-components.${format}.js`,
    },
    rollupOptions: {
      external: [
        'vue', 'vuex',
        'ant-design-vue'
        // 'moment'
      ],
      output: {
        globals: {
          PluginComponents: 'PluginComponents'
        }
      },
    },
    watch: isPrd ? null : {}
  }
})
